package com.baikeyang.common.bean;

import java.io.Serializable;
import java.text.MessageFormat;

public class ResponseResult implements Serializable {

    protected static class ExecuteConstants {
        static final class EXECUTEINFO{
            public static final String 成功 = "SUCCESS";
            public static final String 失败 = "FAIL";
            public static final String 异常 = "ERROR";

            public static final String getInfo(String infoType, String info){
                String template = "{0}:{1}";
                return MessageFormat.format(template, infoType, info);
            }
        }

        /**
         * @Title Constants.java
         * @Project BAPI
         * @Package com.baikeyang.common.bean.ResponseResult
         * @Description TODO 故障码
         * 			故障码规则：
         * 			3+接口序号+ code码
         * 			接口序号不够2位，则用0补齐；
         * 			code码规则：三位数，从100开始；
         * 							1XX 为限制类错误
         * 							2XX 为调用方错误
         * 							3XX 为平台错误
         * 							4XX 为调用误码
         * 			如接口序号2，code码位1，则该故障码为302101
         * @See
         * @Author BaiKeyang@vip.qq.com
         * @ComputerUser lenovo
         * @Time 2016年11月30日 上午10:50:23
         * @Version v1.0.0
         * @Copyright  2016  <a href="http://www.bkybk.com/" target="_blank">Youth Pro. </a>
         */
        static final class EXECUTECODE{
            public static final int CODE_100 = 100;
            public static final int CODE_101 = 101;//指定客户端应相应的某些动作，代表请求已被接受，需要继续处理
            public static final int CODE_102 = 102;
            public static final int CODE_200 = 200;//表示请求已成功，请求所希望的响应头或数据体将随此响应返回
            public static final int CODE_202 = 202;//服务器已接受请求，但尚未处理
            public static final int CODE_400 = 400;
            public static final int CODE_403 = 403;//服务器已经理解请求，但是拒绝执行它
            public static final int CODE_404 = 404;//请求失败，请求所希望得到的资源未被在服务器上发现
            public static final int CODE_500 = 500;
            public static final int CODE_501 = 501;
        }

        static final class EXECUTESTATUS{
            public static final boolean 成功 = true;
            public static final boolean 失败 = false;
        }
    }

    private static final long serialVersionUID = -1209067831575724458L;

    /**
     * 成功标记 true：成功；false：失败
     */
    private boolean status = ExecuteConstants.EXECUTESTATUS.失败;

    /**
     * 消息
     */
    private String info = ExecuteConstants.EXECUTEINFO.失败;

    /**
     * 数据
     */
    private Object data;

    /**
     * 信息码
     */
    private Integer code = ExecuteConstants.EXECUTECODE.CODE_404;

    public ResponseResult(){}

    public ResponseResult(String info, int code){
        this.info = info;
        this.code = code;
    }

    public ResponseResult(boolean status, String info, int code){
        this.status = status;
        this.info = info;
        this.code = code;
    }

    public ResponseResult(boolean status, String info, int code, Object data){
        this.status = status;
        this.info = info;
        this.code = code;
        this.data = data;
    }

    public boolean isStatus() {
        return status;
    }

    public void setStatus(boolean status) {
        this.status = status;
    }

    public String getInfo() {
        return info;
    }

    public void setInfo(String info) {
        this.info = info;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    @Override
    public String toString() {
        return "ResponseResult{" +
                "status=" + status +
                ", info='" + info + '\'' +
                ", data=" + data +
                ", code=" + code +
                '}';
    }
}
